<template>
	<view>
		<view class="no-data" v-show="noDataFlag">
			<uv-empty text="暂无记录" mode="list"></uv-empty>
		</view>
		<view v-for="record in records">
			<view class="goods-info padding-lr32">
				<view class="goods-info-l">
					<image style="width: 180rpx; height: 180rpx;" mode="aspectFit" :src="record.goodsMainPic"></image>
				</view>
				<view class="goods-info-r">
					<view class="goods-name">
						{{record.goodsName}}
						<span>{{record.stateName}}</span>
					</view>
					<view class="quantity-total-amount">
						<view class="quantity">数量X{{record.quantity}}</view>
					</view>
					<view class="state-create-time">	
						<view class="create-time">{{record.createTime}}</view>
						<view class="total-amount">积分：<span>{{record.totalAmount}}</span></view>
					</view>
					<view class="express-number" v-show="record.expressNumber">
						快递单号：{{record.expressNumber}} {{record.expressCompany}}
					</view>
				</view>
			</view>
			<uv-gap height="8" bgColor="#e8e8e8"></uv-gap>
		</view>
		<view @click="nextPage" v-show="!noDataFlag">
			<uv-load-more margin-top="40" margin-bottom="40" :status="loadingState" />
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				records: [],
				pageNum: 1,
				loadingState: 'loadmore',
				pullDownRefreshFlag: false,
				noDataFlag: false,
			}
		},
		onLoad() {
			this.findByPage();
		},
		onReachBottom() {
			this.nextPage();
		},
		onPullDownRefresh() {
			this.pullDownRefreshFlag = true;
			this.refreshData();
		},
		methods: {

			refreshData() {
				this.pageNum = 1;
				this.records = [];
				this.loadingState = 'loading';
				this.findByPage();
			},

			nextPage() {
				if (this.loadingState == 'nomore') {
					return;
				}
				this.pageNum = this.pageNum + 1;
				this.findByPage();
			},

			findByPage() {
				var that = this;
				var queryParam = {
					pageSize: 10,
					pageNum: that.pageNum,
				};
				that.loadingState = 'loading';
				uni.$uv.http.get('/goodsExchangeOrder/findByPage', {
					params: queryParam
				}).then(res => {
					var newRecords = res.data.content;
					var totalPage = res.data.totalPage;
					if (that.pullDownRefreshFlag) {
						that.pullDownRefreshFlag = false;
						uni.stopPullDownRefresh();
					}
					if (newRecords.length == 0) {
						that.loadingState = 'nomore';
					}
					if (totalPage == that.pageNum) {
						that.loadingState = 'nomore';
					}
					var oldRecords = that.records;
					for (var i = 0; i < newRecords.length; i++) {
						var flag = true;
						for (var j = 0; j < oldRecords.length; j++) {
							if (newRecords[i].id == oldRecords[j].id) {
								flag = false;
								break;
							}
						}
						if (flag) {
							oldRecords.push(newRecords[i]);
						}
					}
					that.noDataFlag = that.records.length == 0;
				});
			},

		}
	}
</script>

<style scoped lang="less">
page {
	height: auto !important;
	background-color: #f3f5ff;
}
    *{
		color: #fff;
	}
	.no-data {
		display: flex;
		align-items: center;
		justify-content: center;
		height: 400rpx;
	}

	.goods-info {
		display: flex;
		align-items: center;
		background-color: #FFF;
		width: 88%;
		margin: 0 auto;
		height: 300rpx;
		border-radius: 30rpx;
		.goods-name{
			color: black;
		}
	}

	.goods-info-l {
		flex: 1;
		image{
			border-radius: 40rpx;
		}
	}

	.goods-info-r {
		flex: 2;
		.quantity{
			color: #999999;
		}
		.quantity{
			font-size: 30rpx;
		}
		.state-create-time{
			font-size: 30rpx;
			font-weight: 600;
		}
		.create-time{
			color: #999999;
			font-size: 28rpx;
			font-weight: normal;
		}
		.total-amount{
            color:#000;
			span{
				color: #f36e0e;
			}
		}
		.goods-name span{
			color: #f36e0e;
			float: right;
		}
	}

	.goods-name {
		font-weight: bold;
		padding-bottom: 32rpx;
	}

	.quantity-total-amount {
		display: flex;
		align-items: center;
		justify-content: space-between;
		font-size: small;
		padding-bottom: 32rpx;
	}

	.stock {
		color: #d0021b;
	}

	.price {
		color: #888;
	}

	.state-create-time {
		display: flex;
		align-items: center;
		justify-content: space-between;
		font-size: small;
	}

	.express-number {
		display: flex;
		align-items: center;
		justify-content: space-between;
		font-size: small;
		padding-top: 8rpx;
	}
</style>